#
#    Copyright 2006 Andrew Wilkinson <aw@cs.york.ac.uk>.
#
#    This file is part of PyScobble (http://lastfm.indiegigs.co.uk/pyscrobble)
#
#    PyScobble is free software; you can redistribute it and/or modify
#    it under the terms of the GNU Lesser General Public License as published by
#    the Free Software Foundation; either version 2.1 of the License, or
#    (at your option) any later version.
#
#    PyScobble is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Lesser General Public License for more details.
#
#    You should have received a copy of the GNU Lesser General Public License
#    along with PyScobble; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

from scrobble.utils import *
from scrobble.database import getSimilarArtists

class Artist(object):
    def __init__(self, name, mbid=None):
        self.__name = name
        self.__mbid = mbid

        self.__profile = {"name": name}

    def getLink(self):
        return """<a href="http://www.last.fm/music/%s">%s</a>""" % (self.name, self.name)

    def __getName(self):
        return self.__name
    name = property(__getName)
    def __getMbId(self):
        return self.__mbid
    mbid = property(__getMbId)

    def __getSimilar(self):
        if self.__profile.has_key("similar"):
            return self.__profile["similar"]

        similar = getSimilarArtists(self.__name)
        self.__profile["similar"] = [Artist(f) for f in similar]
        return self.__profile["similar"]
    similar = property(__getSimilar)

    def __hash__(self):
        return hash(self.name)
    def __cmp__(self, other):
        if self.mbid is not None and other.mbid is not None:
            return cmp(self.mbid, other.mbid)
        else:
            return cmp(self.name, other.name)

    def __str__(self):
        return "%s" % (self.name, )
    def __repr__(self):
        return "<scrobble.Artist(%s)" % (repr(self.name), )
